﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoleChoose.aspx.cs" Inherits="ZX.WebApp.EditWidows.SysManager.RoleChoose" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls.UserControl"
    TagPrefix="cc2" %>
<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
    <title></title>
    <!--CSS file (default YUI Sam Skin) -->
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link type="text/css" rel="stylesheet" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link href="../../Scripts/yui_2.9.0/build/treeview/assets/treeview-core.css" rel="stylesheet"
        type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <!-- Source files -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <!-- 工具栏 -->
    <div id="listpage">
        <%--<cc1:TreeView ID="treeDiv1" runat="server" TableName='DatDepartment' Caption='DeptName'
            Key='DeptID' ParentKey='ParentID' path='DeptPath'></cc1:TreeView>--%>
        <cc2:TreeViewMenu ID="TreeViewMenu1" runat="server" TableName="SysRole" Caption="RoleName"
            Key="RoleID" AllowCheck="true"></cc2:TreeViewMenu>
    </div>
    </form>
</body>
<script type="text/javascript">
    var tree2 = null;
    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;

        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                    //{ position: 'left', width: 160, body: 'treeDiv1', gutter: '1 2 1 1', header: '组织架构', collapse: true, scroll: true, zIndex: 1 },
                    { position: 'center', body: 'TreeViewMenu1', gutter: '1 2 1 1', header: '角色列表', scroll: true}]
            });
            layout.render();
        });
        var makeBranch = function (parent, label) {
        }
//        var tree1 = new YAHOO.widget.TreeView("treeDiv1");
//        makeBranch(tree1.getRoot());
//        tree1.setNodesProperty('propagateHighlightUp', true);
//        tree1.setNodesProperty('propagateHighlightDown', true);
//        tree1.subscribe('clickEvent', tree1.onEventToggleHighlight);
//        tree1.render();
        tree2 = new YAHOO.widget.TreeView("TreeViewMenu1");
        makeBranch(tree2.getRoot());
        tree2.setNodesProperty('propagateHighlightUp', true);
        tree2.setNodesProperty('propagateHighlightDown', true);
        tree2.subscribe('clickEvent', tree2.onEventToggleHighlight);
        tree2.render();

            var request = "../../Extend/AjaxData/DataProcessin.aspx?action=Get&entity=SysUserRole&condition=UserID='"+parent.pUserId+"'";
            YAHOO.util.Connect.asyncRequest('POST', request, {
                success: function (res) {
                    var inventory;
                    try {
                        var userIDs = [];
                        var str = res.responseText;
                        var items = eval("["+str+"]");
                        for(var i=0;i<items[0].rows.length;i++)
                        {
                            userIDs.push(items[0].rows[i].RoleID);
                        }
                        checkNode(userIDs.join(","));
                        tree2.render();
                        //inventory = JSON.parse(res.responseText);
                        //alert(inventory);
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("读取菜单数据错误：" + error.statusText);
                }
            }, null);

        })();
        function checkNode(userIDs) {
            var topNodes = tree2.getRoot().children;
            for (var i = 0; i < topNodes.length; ++i) {
                var id = topNodes[i].href.split("#@")[1];
                if (userIDs.indexOf(id) >-1) {
                //for (var node in topNodes) {
                topNodes[i].highlightState = 1;// setNodesByProperty('highlightState');
                }
            }
        }
    var fkey;
    function Native(caption, key) {
        fkey = key;
    }
    function SaveRole() {
        var hiLit = tree2.getNodesByProperty('highlightState', 1);
        if (YAHOO.lang.isNull(hiLit)) {
            alert("None selected");
        } else {
            var labels = [];
            for (var i = 0; i < hiLit.length; i++) {
                var node = tree2.getTreeDefinition();
                labels.push(hiLit[i].href.split("#@")[1]);
            }
            //alert(labels.join(","));
        }
        var url = "../../Extend/AjaxData/DataProcessin.aspx?action=Save&entity=SysUserRole&ids=" + labels + "&userid=" + parent.pUserId + "";
        //alert(parent.pUserId);
        YAHOO.util.Connect.asyncRequest('POST', url, {
            success: function (res) {
                var inventory;
                try {
                    inventory = JSON.parse(res.responseText);
                    if (inventory == 1) {
                        alert("保存成功!");
                        parent.YAHOO.example.container.dialog1.hide();
                    } else {
                        alert("保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("读取菜单数据错误：" + error.statusText);
            }
        }, null);
    }
</script>
</html>
